package com.cskaoyan.controller;


import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.category.CategoryData;
import com.cskaoyan.bean.category.CategoryDateFromLeve1;
import com.cskaoyan.bean.category.CategoryDateInInsert;
import com.cskaoyan.bean.category.CategoryL1Date;
import com.cskaoyan.bean.po.MarketCategory;
import com.cskaoyan.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/category")
public class CategoryController {

    @Autowired
    CategoryService categoryService;

    /**oushao 2022-06-04-22:54
     * /admin/category/list
     * @return 返回商品的类目
     */
    @GetMapping("list")
    public BaseRespVo list(){
        CategoryData categoryData = categoryService.queryList();
        BaseRespVo<Object> objectBaseRespVo = new BaseRespVo<>();
        objectBaseRespVo.setErrmsg("成功");
        objectBaseRespVo.setErrno(0);
        objectBaseRespVo.setData(categoryData);
        return objectBaseRespVo;
    }

    @PostMapping("create")
    public BaseRespVo creat(@RequestBody() MarketCategory marketCategory){

        MarketCategory marketCategory1 = categoryService.insert(marketCategory);
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setData(marketCategory1);
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        return baseRespVo;

    }

    @PostMapping("update")
    public BaseRespVo update(@RequestBody() MarketCategory marketCategory){

        categoryService.update(marketCategory);

        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        return baseRespVo;
    }

    @GetMapping("l1")
    public BaseRespVo l1(){

        CategoryL1Date categoryL1Date = categoryService.queryLevel1();

        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setData(categoryL1Date);
        return baseRespVo;

    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody() MarketCategory marketCategory){

        categoryService.delete(marketCategory);

        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        return baseRespVo;

    }

}
